<? 
	include('base.php');
	User::protect();
	$section = 'band_diaries';
	include_class('band_diaries');
	include_class('band_members');
	$bd = BandMemberDiary::get($_GET['id']);

	if (!db::isError($bd)) {
		switch ($_GET['task']) {
			case 'update':
				$res = $bd->update($_POST);
				if (!db::isError($res)) {
					header('Location: band_diary_edit.php?id=' . $_GET['id']);
				}
				break;
			case 'deactivate':
				$res = $bd->deactivate();
				if (!db::isError($res)) {
					header('Location: band_diary_edit.php?id=' . $_GET['id']);
				}
				break;
			case 'activate':
				$res = $bd->activate();
				if (!db::isError($res)) {
					header('Location: band_diary_edit.php?id=' . $_GET['id']);
				}
				break;
			case 'delete':
				$res = $bd->remove();
				if (!db::isError($res)) {
					header('Location: band_diaries.php');
				}
				break;
		}
	}
	$calendar = true;
	$editors = array('body');
	$page_title = 'View/Edit Band Diaries';
	include('layout/header.php');
?>
<? 	if (!db::isError($bd)) { 
	$bm = $bd->getMemberObject();
	$uo = $bm->getUserObject();
?>

<div id="breadcrumb">
	<a href="index.php">Audition&nbsp;&#62;</a>&nbsp;<a href="band.php">Manage&nbsp;Band&nbsp;&#62;</a>&nbsp;<a href="band_diaries.php">Diaries&nbsp;&#62;</a>&nbsp;<a href="band_diaries.php?memberID=<?=$bm->getID()?>"><?=$uo->getFirstName()?>'s Diary&nbsp;&#62;</a>&nbsp;View Entry
</div>

<?

if (db::isError($res)) {
	$res->outputList();
}

if ((($_GET['task'] == 'edit') || $_GET['task'] == 'update') && $bd->canEdit()) { 
	
		$title = ($_POST) ? $_POST['title'] : $bd->getTitle();
		$date = ($_POST) ? $_POST['date'] : $bd->getDate();
		$time = ($_POST) ? $_POST['time'] : $bd->getTime();
		$title = ($_POST) ? $_POST['title'] : $bd->getTitle();
		$body = ($_POST) ? $_POST['body'] : $bd->getBody();
		
			
		?>
		
		<h1>edit diary entry:</h1>
		<div class="inset">
		<form id="edit_entry" action="<?=$_SERVER['PHP_SELF']?>?task=update&amp;id=<?=$_GET['id']?>" method="post">
		<table border="0" class="edit-form" cellspacing="0" cellpadding="0">
		<? if (!$bd->isActive()) { ?>
		<tr>	
			<td>&nbsp;</td>
			<td colspan="2" class="fieldname">This entry is inactive.</td>
		</tr>
		<? } ?>
		<tr>
			<td colspan="3" valign="top">
			<strong>Headline</strong><br/>
			<input type="text" value="<?=$title?>" class="text" name="title">
			</td>
		</tr>
		<tr>
			<td width="50%" valign="top">
			
			<strong>Date (<a style="vertical-align: middle" href="javascript:void(0)" onclick="popUpCalendar(this, document.getElementById('date'), '<?=DATE_JS_CALENDAR?>')">Calendar</a>)</strong><br/>
			<input name="date" id="date" class="text" type="text" value="<?=$date?>">
			
			</td>
			<td width="50%" valign="top">
						
			<strong>Time</strong><br/>
			<input name="time" id="time" class="text" type="text" value="<?=$time?>">
			</td>

		</tr>
		</table>
		<div class="edit-form">
		<strong>Body</strong><br/><textarea id="body" name="body" class="full"><?=$body?></textarea>
		</div>
		
		<input type="submit" value="Update Entry" name="submit" class="button">
		<input type="submit" class="button" value="Exit Without Updating" name="preview" onclick="location.href='<?=$PHP_SELF?>?id=<?=$bd->getID()?>'; return false" class="button">
		</form>
		</div>

	<? } else { ?>

		<h1>view diary entry:</h1>
		<div class="inset">
		
		<h2><?=$bd->getTitle()?></h2>
		<span class="small">
			Posted By <?=$uo->getFirstName()?> on <?=$bd->getDateTime()?><br>
			Status: <? if ($bd->isActive()) { ?><b>Active</b><? } else { ?><b>Inactive</b><? } ?>
		</span>
		<br><br>
		<? if ($bd->getBody()) { ?>
			<b>Body:</b><br>
			<?=$bd->getBody()?><br><br>
		<? } ?>
		<form name="entry_status" method="get">
			<? if ($bd->canEdit()) { ?>
				<input type="submit" name="" value="Edit Entry" onclick="location.href='<?=$_SERVER['PHP_SELF']?>?task=edit&id=<?=$_GET['id']?>';return false" class="button">
				<? if ($bd->isActive()) { ?><input type="submit" name="" value="Deactivate Entry" onclick="location.href='<?=$PHP_SELF?>?task=deactivate&id=<?=$_GET['id']?>';return false" style="margin-right: 5px"><? } else { ?><input type="submit" name="" value="Activate Entry" onclick="location.href='<?=$PHP_SELF?>?task=activate&id=<?=$_GET['id']?>';return false" class="button"><? } ?>
			<input type="submit" value="Remove Entry" name="" onclick="if (confirm('Are you sure you wish to delete this entry?')) { location.href='<?=$PHP_SELF?>?task=delete&id=<?=$_GET['id']?>'};return false" class="button">
		<? } ?>
		<input type="submit" value="Return to News List" name="" onclick="location.href='band_diaries.php'; return false" class="button">
		</form>
		
		</div>
		
	<? } ?>
		
<? } else { ?>

<div id="breadcrumb">
	<a href="index.php">Audition&nbsp;&#62;</a>&nbsp;<a href="band.php">Manage&nbsp;Band&nbsp;&#62;</a>&nbsp;<a href="band_diaries.php">Diaries&nbsp;&#62;</a>&nbsp;Invalid Entry
</div>

	<?=$bd->outputDialog('Return to Band Diaries','band_diaries.php')?>

<? } ?>

<? include('layout/footer.php'); ?>
